package com.thesis.manage.common.utils;

/**
 * @author php
 * @date 2018/1/2
 * 耗时计算工具（可以跨类和方法）
 */
public class TimeConsumUtil {
    private static final ThreadLocal<Long> THREAD_LOCAL;

    static {
        THREAD_LOCAL = ThreadLocal.withInitial(System::currentTimeMillis);
    }

    public static void begin() {
        THREAD_LOCAL.set(System.currentTimeMillis());
    }

    public static Long end() {
        long time;
        try {
            time = System.currentTimeMillis() - THREAD_LOCAL.get();
        } finally {
            THREAD_LOCAL.remove();
        }
        return time;
    }

}
